import {reqAdressInfo,reqOrderInfo,reqOrderSubmit} from '@/api/index'

let state={
  AddressList:[],
  orderList:{},
  orderCode:''
}

let actions={
   //获取用户地址信息
   async getAddressInfo(context){
      let result=  await reqAdressInfo()

      if(result.code==200){
      
        context.commit('GETADDRESSINFO',result.data)
        return 'ok'
      }
      else{
        return Promise.reject(new Error(result.message))
      }
    },
  //获取订单交易页信息
 async getOrderInfo(context){

    let result= await reqOrderInfo()

    if(result.code==200){
       context.commit('GETORDERINFO',result.data)
     
    }
    

  },
  //提交订单
  async orderSubmit(context,{tradeNo,data}){

    
  let  result =  await  reqOrderSubmit(tradeNo,data)
  console.log(result)
    if(result.code==200){
     
        context.commit('ORDERSUBMIT',result.data)
    }
  }
}

let mutations={
  GETADDRESSINFO(state,AddressList){
    state.AddressList=AddressList

  },
  GETORDERINFO(state,orderList){
    state.orderList=orderList
  },
  ORDERSUBMIT(state,orderCode){
    state.orderCode=orderCode
  }
}

let getters={
  detailArrayList(state){
    return state.orderList.detailArrayList
  }

}

export default{
  state,
  actions,
  mutations,
  getters
}
